package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PurchaseMt;
import com.ruoyi.system.service.IPurchaseMtService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-19
 */
@RestController
@RequestMapping("/system/mt")
public class PurchaseMtController extends BaseController
{
    @Autowired
    private IPurchaseMtService purchaseMtService;

    /**
     * 查询采购管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:mt:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseMt purchaseMt)
    {
        startPage();
        List<PurchaseMt> list = purchaseMtService.selectPurchaseMtList(purchaseMt);
        return getDataTable(list);
    }

    /**
     * 导出采购管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:mt:export')")
    @Log(title = "采购管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseMt purchaseMt)
    {
        List<PurchaseMt> list = purchaseMtService.selectPurchaseMtList(purchaseMt);
        ExcelUtil<PurchaseMt> util = new ExcelUtil<PurchaseMt>(PurchaseMt.class);
        util.exportExcel(response, list, "采购管理数据");
    }

    /**
     * 获取采购管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mt:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Integer supplierId)
    {
        return AjaxResult.success(purchaseMtService.selectPurchaseMtBySupplierId(supplierId));
    }

    /**
     * 新增采购管理
     */
    @PreAuthorize("@ss.hasPermi('system:mt:add')")
    @Log(title = "采购管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseMt purchaseMt)
    {
        return toAjax(purchaseMtService.insertPurchaseMt(purchaseMt));
    }

    /**
     * 修改采购管理
     */
    @PreAuthorize("@ss.hasPermi('system:mt:edit')")
    @Log(title = "采购管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseMt purchaseMt)
    {
        return toAjax(purchaseMtService.updatePurchaseMt(purchaseMt));
    }

    /**
     * 删除采购管理
     */
    @PreAuthorize("@ss.hasPermi('system:mt:remove')")
    @Log(title = "采购管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Integer[] supplierIds)
    {
        return toAjax(purchaseMtService.deletePurchaseMtBySupplierIds(supplierIds));
    }
}
